package com.csdj.controller.Be;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.csdj.common.enums.AppHttpCodeEnum;
import com.csdj.common.utils.ResponseResult;
import com.csdj.pojo.BeOrderuser;
import com.csdj.service.BeOrderuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/beOrderUser")
public class BeOrderUserController {
    @Autowired
    private BeOrderuserService beOrderuserService;

    /**
     * 根据工单单号获取所有用户
     * @param orderNo 工单单号
     */
    @GetMapping
    public ResponseResult getAllByOrderNo(String orderNo){
        LambdaQueryWrapper<BeOrderuser> l=new LambdaQueryWrapper<>();
        l.eq(BeOrderuser::getOrderNo,orderNo);
        List<BeOrderuser> list = beOrderuserService.list(l);
        return list.isEmpty()?ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"服务器繁忙"):ResponseResult.okResult(list);
    }
    /**
     * 根据名字获取所有用户
     * @param name 工单单号
     */
    @GetMapping("/byName")
    public ResponseResult getAllByName(String name){
        LambdaQueryWrapper<BeOrderuser> l=new LambdaQueryWrapper<>();
        l.eq(BeOrderuser::getUserName,name);
        List<BeOrderuser> list = beOrderuserService.list(l);
        return list.isEmpty()?ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"服务器繁忙"):ResponseResult.okResult(list);
    }
}
